//
// Created by Tony on 2024/5/25.
//

#ifndef PARSER_FUNCTION_DEFINE_H
#define PARSER_FUNCTION_DEFINE_H

#include "../../AstList.h"
#include "../../leaf/Name.h"
#include "../../list/stmt/BlockStmt.h"
#include "ParameterList.h"
#include <cstdint>

namespace Parser {

class FunctionDefine final : public AstList {
    string nodeName;
    shared_ptr<Compiler::SymbolTable> symbolTable;
    int32_t classId{-1};

public:
    explicit FunctionDefine(const vector<shared_ptr<Ast>>& children) : AstList(children) {
        nodeName = __func__;
    }

    shared_ptr<Name> name() { return static_pointer_cast<Name>(children[0]); }

    shared_ptr<ParameterList> parameterList() {
        return static_pointer_cast<ParameterList>(children[1]);
    }

    shared_ptr<TypeTag> returnTypeTag() { return static_pointer_cast<TypeTag>(children[2]); }

    shared_ptr<BlockStmt> block() { return static_pointer_cast<BlockStmt>(children[3]); }

    void setSymbolTable(const shared_ptr<Compiler::SymbolTable>& table) {
        this->symbolTable = table;
    }

    shared_ptr<Compiler::SymbolTable> getSymbolTable() { return symbolTable; }

    void setClassId(int32_t id) { this->classId = id; }

    int32_t getClassId() const { return classId; }

    int32_t accept(Compiler::Visitor* visitor) override;
};

} // namespace Parser

#endif // PARSER_FUNCTION_DEFINE_H
